package com.neusoft.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.entity.User;
import com.neusoft.entity.UserExample;
import com.neusoft.mapper.UserMapper;
import com.neusoft.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	UserMapper userServiceMapper;

	@Override
	@Transactional // 加入事务管理器, 如果出异常,自动回滚
	public int removeByUserId(Integer uId) {
		return userServiceMapper.deleteByPrimaryKey(uId);
	}

	@Override
	public int addSelective(User record) {
		return userServiceMapper.insertSelective(record);
	}

	@Override
	public int updateByUserIdSelective(User record) {
		return userServiceMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public User loadByUserId(Integer uId) {
		return userServiceMapper.selectByPrimaryKey(uId);
	}

	@Override
	public List<User> loadListByExample(String account, String password) {
		UserExample example = new UserExample();
		UserExample.Criteria uc = example.createCriteria();
		uc.andUAccountEqualTo(account);
		uc.andUPasswordEqualTo(password);
		return userServiceMapper.selectByExample(example);
	}

}
